package com.zmc.lostfound.post.controller;

import com.zmc.lostfound.post.entity.ItemTypeEntity;
import com.zmc.lostfound.post.service.ItemTypeService;
import com.zmc.lostfound.post.vo.ItemTypeSaveVO;
import com.zmc.lostfound.common.utils.PageParams;
import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LJQ
 * @description 物品类型管理接口
 * @email 1205329889@qq.com
 * @date 2023-07-05 15:09:50
 */
@RestController
@RequestMapping("/itemType")
@Api(value = "物品类型管理接口", tags = "物品类型管理接口")
public class ItemTypeController {

    private final ItemTypeService itemTypeService;

    public ItemTypeController(ItemTypeService itemTypeService) {
        this.itemTypeService = itemTypeService;
    }

    @ApiOperation("分页模糊查询物品类型")
    @PostMapping("/query/page")
    public Result queryPage(@RequestBody @Validated PageParams pageParams) {
        PageResult pageResult = itemTypeService.queryPage(pageParams);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("查询全部物品类型")
    @GetMapping("/query/all")
    public Result queryAll() {
        List<ItemTypeEntity> itemTypeInfoList = itemTypeService.findAll();
        return Result.ok("查询成功").put("itemTypeInfoList", itemTypeInfoList);
    }

    @ApiOperation("按主键id查询物品类型")
    @GetMapping("/query/info/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        ItemTypeEntity itemTypeInfo = itemTypeService.queryInfoById(id);
        return Result.ok("查询成功").put("itemTypeInfo", itemTypeInfo);
    }

    @ApiOperation("新增物品类型")
    @PostMapping("/insertItemType")
    public Result insertItemType(@RequestBody @Validated(value = {AddGroup.class}) ItemTypeSaveVO itemTypeSaveVO) {
        return itemTypeService.insertItemType(itemTypeSaveVO);
    }

    @ApiOperation("修改物品类型")
    @PutMapping("/updateItemType")
    public Result updateItemType(@RequestBody @Validated(value = {UpdateGroup.class}) ItemTypeSaveVO itemTypeSaveVO) {
        return itemTypeService.updateItemType(itemTypeSaveVO);
    }

    @ApiOperation("批量删除物品类型")
    @DeleteMapping("/deleteBatchByIds")
    public Result deleteBatchByIds(@RequestBody List<Long> itemTypeIds) {
        return itemTypeService.deleteBatchItemType(itemTypeIds);
    }

}
